<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div class="container"></div>

  <script type="text/html" id="tpl-box">
    <h2>我是标题--{{time | dateFormat}}</h2>
  </script>

  <script src="./lib/jquery.js"></script>
  <script src="./lib/template-web.js"></script>

  <script>
    let data = {
      time: new Date()
    }

    template.defaults.imports.dateFormat = function(date){
      // padStart(3, 0)  如果不够3位。则前边补0
      let time = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`

      return time
    }

    let str = template('tpl-box', data)

    $('.container').html(str)
  </script>
</body>
</html>